The IDL “=” operator is unable to assign a structure value to a structure of a different type. The STRUCT_ASSIGN procedure performs “relaxed structure assignment,” which is a field-by-field copy of a structure to another structure. Fields are copied according to the following rules:
Relaxed structure assignment is especially useful when restoring structures from disk files into an environment where the structure definition has changed. See the description o f the RELAXED_STRUCTURE_ASSIGNMENT keyword to the RESTORE procedure for additional details. Relaxed Structure Assignment provides a more in-depth discussion of the structure-definition process.
STRUCT_ASSIGN, Source, Destination [, /NOZERO] [, /VERBOSE]
A named variable or element of an array containing a structure, the contents of which will be assigned to the structure specified by the Destination argument. Source can be an object reference if STRUCT_ASSIGN is called inside an object method.
A named variable containing a structure into which the contents of the structure specified by the Source argument will be inserted. Destination can be an object reference if STRUCT_ASSIGN is called inside an object method.
Normally, any fields found in the destination structure that are not found in the source structure are zeroed. Set NOZERO to prevent this action and leave the original contents of such fields unchanged.
Set this keyword to cause STRUCT_ASSIGN to issue informational messages about any incompatibilities that prevent data from being copied.
The following example creates two anonymous structures, then uses STRUCT_ASSIGN to insert the contents of the first into the second:
source = { a:FINDGEN(4), b:12 }
dest = { a:INDGEN(2), c:20 }
STRUCT_ASSIGN, /VERBOSE, source, dest
IDL prints:
% STRUCT_ASSIGN: <Anonymous> tag A is longer than destination.
The end will be clipped.
% STRUCT_ASSIGN: Destination lacks <Anonymous> tag B. Not copied.
After assignment, dest contains a two-element integer array [0, 1] in its field A and the integer 0 in its field C. Since dest does not have a field B, field B from source is not copied.
5.1 |
Introduced |